import { create } from 'zustand';

const useDeviceStore = create((set) => ({
  devices: [
    {
      id: '1',
      name: '设备1',
      manufacturer: '厂商A',
      description: '这是设备1的描述',
      isRecommended: true,
      isDisplayed: true,
      images: [],
    },
    {
      id: '2',
      name: '设备2',
      manufacturer: '厂商B',
      description: '这是设备2的描述',
      isRecommended: false,
      isDisplayed: true,
      images: [],
    },
  ],

  addDevice: (device) => set((state) => ({
    devices: [...state.devices, {
      ...device,
      id: Date.now().toString(),
      isRecommended: false,
      isDisplayed: true,
    }]
  })),

  editDevice: (id, updatedDevice) => set((state) => ({
    devices: state.devices.map(device => 
      device.id === id ? { ...device, ...updatedDevice } : device
    )
  })),

  deleteDevice: (id) => set((state) => ({
    devices: state.devices.filter(device => device.id !== id)
  })),

  toggleRecommended: (id) => set((state) => ({
    devices: state.devices.map(device => 
      device.id === id ? { ...device, isRecommended: !device.isRecommended } : device
    )
  })),

  toggleDisplayed: (id) => set((state) => ({
    devices: state.devices.map(device => 
      device.id === id ? { ...device, isDisplayed: !device.isDisplayed } : device
    )
  })),
}));

export default useDeviceStore;